package o2o.hx.cron.core.zookeeper.listener;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.log4j.Logger;

public class NodeLockZkListener implements IZKListener {
	private static Logger logger = Logger.getLogger(NodeLockZkListener.class);
	private String path = "/cron";
	public void setPath(String path) {
		this.path = path;
		
	}
	@Override
	public void executor(CuratorFramework client) {
		try {
			@SuppressWarnings("resource")
			
			final NodeCache cache = new NodeCache(client, path);
			cache.getListenable().addListener(new NodeCacheListener() {
				public void nodeChanged() throws Exception {
					System.out.println(new String(cache.getCurrentData().getData()));
				}
			});
			cache.start();
		} catch (Exception e) {
			logger.error(e);
		}
	}

}
